import mui from '@/assets/mui/js/mui.js'
import '@/assets/font_937327_9xsqwsz69/iconfont.css'
import '@/assets/mui/css/mui.css'
import Vue from 'vue/dist/vue.js';
import App from './App'
import VueRouter from 'vue-router'
import common from './commonFunc/common.js'

import VueResource from 'vue-resource'
import Home from './components/Home'
import Login from './components/Login'
import AddNote from './components/AddNote'
import EditNote from './components/EditNote'
import Search from './components/Search'
import DetailNote from './components/DetailNote'
import Center from './components/Center'

Vue.config.productionTip = false
//定义全局mui
Vue.prototype.mui = mui
Vue.prototype.common = common;

Vue.use(VueResource)
Vue.use(VueRouter);

const routes = [
  {
    path: '/', component: Home,
    beforeEnter: (to, from, next) => {
      if (sessionStorage.getItem('userId')) {
        next('/home');
      } else {
        next('/login');
      }
    }
  },
  {
    path: '/home',
    name: 'home',
    component: Home,
    beforeEnter: (to, from, next) => {
      console.log("-----" + sessionStorage.getItem('userId') + '----');
      if (sessionStorage.getItem('userId')) {
        next();
      } else {
        next('/login');
      }
    }
  },
  { path: '/login', name: 'loginLink', component: Login },
  { path: '/addNote', name: 'addNoteLink', component: AddNote },
  { path: '/noteEdit/:note', name: 'noteEdit', component: EditNote },
  { path: '/search', name: 'search', component: Search },
  { path: '/noteDetail/:note', name: "noteDetail", component: DetailNote },
  { path: '/center', component: Center }
]
//定义路由
const router = new VueRouter({
  routes,
  mode: 'history'
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  components: { App },
  template: '<App/>',
  router,
})
